package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.ex.ServiceException;
import cn.tedu.csmall.product.pojo.dto.AlbumAddNewDTO;
import cn.tedu.csmall.product.pojo.dto.BrandAddNewDTO;
import cn.tedu.csmall.product.pojo.dto.BrandUpdateDTO;
import cn.tedu.csmall.product.pojo.vo.AlbumListItemVO;
import cn.tedu.csmall.product.pojo.vo.BrandListVO;
import cn.tedu.csmall.product.pojo.vo.BrandStandardVO;
import cn.tedu.csmall.product.service.IBrandService;
import cn.tedu.csmall.product.service.impl.BrandServiceImpl;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * ClassName: BrandController
 * Package: cn.tedu.csmall.product.controller
 * Description
 *
 * @version 0.0.1
 * @Author: 大傻
 * @Create:2022/11/30
 */
@Api(tags = "02.品牌管理模块")
@RequestMapping("/brands")
@RestController
@Validated
@Slf4j
public class BrandController {
    @Autowired
    private IBrandService brandService;
    // http://localhost:9080/brands/add-new
    @ApiOperation("添加品牌")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult addNew(@Valid BrandAddNewDTO brandAddNewDTO){
        brandService.addNew(brandAddNewDTO);
        return JsonResult.ok();
    }

    // http://localhost:9080/brands/1998/delete
  @ApiOperation("删除品牌")
  @ApiOperationSupport(order = 200)
  @ApiImplicitParam(name = "id", value = "品牌ID", required = true, dataType = "long")
  @PostMapping("/{id:[0-9]+}/delete")
  public JsonResult delete(@PathVariable Long id){
        log.debug("开始处理根据id删除品牌请求,参数{}",id);
        brandService.delete(id);
        return JsonResult.ok();
  }
    // http://localhost:9080/brands/1998/enable
    @ApiOperation("启动品牌")
    @ApiOperationSupport(order = 310)
    @ApiImplicitParam(name = "id", value = "品牌ID", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/enable")
    public JsonResult setEnable(@PathVariable Long id){
        log.debug("开始处理【启动品牌】的业务，参数：{}", id);
       brandService.setEnable(id);
        return JsonResult.ok();
    }
    // http://localhost:9080/brands/1998/disable
    @ApiOperation("禁用品牌")
    @ApiOperationSupport(order = 311)
    @ApiImplicitParam(name ="id",value = "品牌id",required = true,dataType = "long")
    @PostMapping("/{id:[0-9]+}/disable")
    public JsonResult setDisable(@PathVariable Long id){
        log.debug("开始处理 禁用品牌的业务,参数:{}",id);
        brandService.setDisable(id);
        return JsonResult.ok();
    }

    // http://localhost:9080/brands/1998/update
    @ApiOperation("修改品牌")
    @ApiOperationSupport(order = 312)
    @ApiImplicitParam(name ="id",value = "品牌id",required = true,dataType = "long")
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult UpdateInfoById(@PathVariable Long id , @Validated BrandUpdateDTO brandUpdateDTO){
        log.debug("开始处理 修改品牌的业务,参数:{}",id);
       brandService.update(id, brandUpdateDTO);
        return JsonResult.ok();
    }

    //http://localhost:9080/brands/1998
    @ApiOperation("根据id查询品牌详情")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParam(name ="id",value = "品牌id",required = true,dataType = "long")
    @GetMapping("/{id:[0-9]+}")
    public JsonResult getStandardById(@PathVariable Long id){
        log.debug("开始处理根据id查询品牌详情请求,参数:{}",id);
        BrandStandardVO BrandStandardVO = brandService.getStandardById(id);

        return JsonResult.ok(BrandStandardVO);
    }

    //http://localhost:9080/brands
    @ApiOperation("查询品牌列表")
    @ApiOperationSupport(order = 420)
    @GetMapping("")
    public JsonResult list(){
        log.debug("开始处理查询品牌列表请求,参数:无");
        List<BrandListVO> list = brandService.list();

        return JsonResult.ok(list);
    }

}
